extends CharacterBody2D

@onready var _animated_sprite = $AnimatedSprite2D

const SPEED = 300.0
@export var JUMP_VELOCITY = -400.0
@export var grivatyScl : float = 1

func _ready():
	_animated_sprite.play("run")
	velocity.x = SPEED

func _physics_process(delta: float) -> void:
	
	# Add the gravity.
	if not is_on_floor():
		velocity += get_gravity()*grivatyScl * delta

	# Handle jump.
	if Input.is_action_just_pressed("ui_up") and is_on_floor():
		velocity.y = JUMP_VELOCITY
	
	velocity.x = SPEED
	
	move_and_slide()

#sneak
var down : bool = false
func _on_button_left_button_down() -> void:
	Input.action_press("ui_down")
	down = true
	if is_on_floor():
		scale = Vector2(0.5, 0.5)

func _on_button_left_button_up() -> void:
	Input.action_release("ui_down")
	down = false
	if is_on_floor():
		scale = Vector2(1, 1)

func _on_button_right_button_down() -> void:
	Input.action_press("ui_up")

func _on_button_right_button_up() -> void:
	Input.action_release("ui_up")
